package com.coai.common.event

import java.time.Instant
import java.util.UUID

/**
 * 业务事件基类
 */
abstract class BusinessEvent(
    val id: String = UUID.randomUUID().toString(),
    val timestamp: Instant = Instant.now(),
    val correlationId: String,
    val causationId: String? = null,
    val userId: String,
    val tenantId: String
) {
    abstract val eventType: String
    abstract val aggregateId: String
    abstract val aggregateType: String
}

/**
 * 事件元数据
 */
data class EventMetadata(
    val timestamp: Instant,
    val userId: String,
    val correlationId: String,
    val causationId: String?,
    val businessContext: Map<String, Any> = emptyMap()
)

/**
 * 领域事件接口
 */
interface DomainEvent {
    val occurredOn: Instant
    val aggregateId: String
}

/**
 * 业务节点类型
 */
enum class BusinessNode(val description: String) {
    // 电商节点
    PRODUCT_BROWSING("商品浏览"),
    ADD_TO_CART("加入购物车"),
    ORDER_CREATION("订单创建"),
    PAYMENT("支付"),
    ORDER_CONFIRMATION("订单确认"),
    
    // 仓储节点
    INVENTORY_RECEIVING("入库"),
    INVENTORY_STORAGE("存储"),
    INVENTORY_PICKING("拣货"),
    INVENTORY_PACKING("打包"),
    INVENTORY_SHIPPING("出库"),
    
    // 采购节点
    PROCUREMENT_REQUEST("采购申请"),
    SUPPLIER_SELECTION("供应商选择"),
    RFQ_SENT("询价发送"),
    QUOTATION_RECEIVED("报价接收"),
    PO_CREATION("采购订单创建"),
    GOODS_RECEIVING("收货"),
    QUALITY_INSPECTION("质检"),
    
    // 生产节点
    PRODUCTION_PLANNING("生产计划"),
    MATERIAL_REQUISITION("领料"),
    PRODUCTION_START("生产开始"),
    PROCESS_CHECKPOINT("工序检查点"),
    QUALITY_CHECK("质量检验"),
    PRODUCTION_COMPLETION("生产完工"),
    
    // 物流节点
    SHIPMENT_CREATION("发货单创建"),
    CARGO_LOADING("装车"),
    TRANSPORTATION_START("运输开始"),
    DELIVERY_COMPLETED("配送完成"),
    
    // 客服节点
    CUSTOMER_INQUIRY("客户咨询"),
    TICKET_CREATION("工单创建"),
    ISSUE_RESOLUTION("问题解决")
}
